<extend name="Layout:base_edit" />
<block name="body_before_block">
    <script src="__THEME__Plugin/Tree-1.0.js" type="text/javascript"></script>
</block>
<block name="body_content_block">
    <div id="tip" style="color:#F00; margin-bottom:5px;">正在加载中,请稍后...</div>
    <div id="bar">
        <input type="checkbox" title="全选/取消全选" style="vertical-align: middle; margin:0px 5px;" onclick="tree.tree_check(this.checked)" />全选
    </div>
    <form method="post" action="{:U('Role/save_role_permission')}" data-reload-grid="false" data-before-submit="get_checked()">
        <ul id="main_tree" data-url="{:U('Role/get_role_permission_list_json','id='.$id)}"></ul>
        <input type="hidden" name="id" value="{$id}" />
        <input type="hidden" name="ids" />
    </form>
</block>
<block name="body_after_block">
    <script type="text/javascript">
        item_form.resize_owner_dialog({"width": 420, "height": 400});
        // 页面初始化
        var tree = Tree.newInstance();
        tree.set_tree_config({
            onBeforeLoad: function () {
                $('#tip').text('正在加载中,请稍后...');
                $('#bar').hide();
            },
            onLoadSuccess: function () {
                $('#tip').text('注意：请确保所有关联层级都按需勾选!');
                $('#bar').show();
            },
            onLoadError: function (msg) {
                $('#tip').html(msg.statusText);
            },
        });
        tree.init();
        function get_checked(){
            $('input[name="ids"]').val(tree.get_checked());
        }
    </script>
</block>